package com.dps.omc.utils.jdbc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by DXH on 2016/5/19.
 */
@Service
public class JdbcServiceManager {

    @Autowired
    private CSMySQL csMySQL;
    @Autowired
    private CSOracle csOracle;

    private JdbcService getInstance(String dbType)
    {
        if(dbType.equals("mysql"))
        {
            return csMySQL;
        }
        else if(dbType.equals("oracle"))
        {
            return csOracle;
        }
        else
        {
            return null;
        }
    }

    public String testConnect(JdbcConnect jdbcConnect)
    {
        JdbcService jdbcService = getInstance(jdbcConnect.getDbType());
        if(jdbcService == null)
        {
            return "暂不支持该种数据库类型！";
        }
        boolean res = jdbcService.testConnect(jdbcConnect);
        if(res)
        {
            return "连接成功！";
        }
        else
        {
            return "连接失败，请检查参数！";
        }
    }
}
